package itbour.onetouchshow.adapter.base.recycler;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import itbour.onetouchshow.adapter.base.BaseAdapterHelper;
import itbour.onetouchshow.adapter.base.multi.BaseItemViewDelegate;


/**
 * Abstraction class of a RecyclerView.Adapter in which you only need
 * to provide the convert() implementation.<br/>
 * Using the provided BaseAdapterHelper, your code is minimalist.
 *
 * @param <T> The type of the items in the list.
 */
public abstract class RecyclerAdapter<T> extends QuickRecyclerAdapter<T, BaseAdapterHelper> {

    public RecyclerAdapter(Context context, int layoutResId) {
        super(context, layoutResId);
    }

    public RecyclerAdapter(Context context, int layoutResId, List<T> data) {
        super(context, layoutResId, data);
    }

    @Override
    protected BaseAdapterHelper getAdapterHelper(int viewType, ViewGroup parent) {
        int res;
        if (hasMultiItemType()) {
            BaseItemViewDelegate<T, BaseAdapterHelper> delegate = delegateManager.getItemViewDelegate(viewType);
            res = delegate.getItemViewLayoutId();
        } else {
            res = layoutResId;
        }

        return BaseAdapterHelper.get(context, null, parent, res);
    }

    @Override
    protected BaseAdapterHelper getHeaderViewHolder(ViewGroup parent, View content) {
        return BaseAdapterHelper.get(parent.getContext(), null, parent, content);
    }

    @Override
    protected BaseAdapterHelper getFooterViewHolder(ViewGroup parent, View content) {
        return BaseAdapterHelper.get(parent.getContext(), null, parent, content);
    }
}
